# -*- coding: utf-8 -*-
# filename: handle.py
import json
import web

act_data_dict = {'action': ''}


def getHtmlPage():
    with open("index.html", "rb") as fs:
        HTML_PAGE = fs.read()
    return HTML_PAGE


def getAction():
    with open("action.data", "rb") as fs:
        ACTION_DATA = fs.read()
    return ACTION_DATA


def getPng(fn):
    with open(fn, "rb") as fs:
        PNG_DATA = fs.read()
    return PNG_DATA


class Handle(object):
    def GET(self, fn):
        # print '<Handle>get'
        # print fn
        if fn != '':
            # print "no null"
            if "favicon.ico" in fn:
                print "favicon.ico"
            elif "png" in fn:
                return getPng(fn)
            elif "action" in fn:
                action = getAction()
                # print action
                act_data_dict['action'] = action
                return json.dumps(act_data_dict)
            else:
                pass
        return getHtmlPage()

    def POST(self, fn):
        # print '<Handle>post'
        # print fn
        # postData = web.input()
        # cmd = postData['cmd']
        # print cmd
        return getHtmlPage()
